package org.darcy.controller.privilege;

import java.util.List;

import org.darcy.controller.BaseController;
import org.darcy.entity.privilege.SysMenu;
import org.darcy.framework.model.R;
import org.darcy.service.privilege.SysMenuService;
import org.darcy.vo.CheckExistVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "SysMenuController接口：菜单")
@RestController
@RequestMapping("/privilege/module")
@Slf4j
public class SysMenuController extends BaseController<SysMenu> {

	private final String info_prefix = "[菜单模块]";

	@Autowired
	private SysMenuService SysMenuService;

	@Operation(summary = "菜单列表（所有，不分页）")
	@PostMapping(value = "list")
	public R list(@RequestBody SysMenu param) {
		log.debug("{}-列表数据", info_prefix);
		List<SysMenu> data = SysMenuService.getAll(param);
		return R.ok().data(data);
	}

	@Operation(summary = "用户详情")
	@GetMapping("/view/{id}")
	public R view(@PathVariable Integer id) {
		log.debug("{}-查看用户信息", info_prefix);
		SysMenu data = SysMenuService.getById(id);
		return R.ok().data(data);
	}

	@Operation(summary = "新增菜单")
	@PostMapping("add")
	public R add(@RequestBody SysMenu record) {
		log.debug("{}-新增SysMenu: {}", info_prefix, record);
		SysMenuService.insert(record);
		return R.ok("新增成功").data(record);
	}

	@Operation(summary = "根据ID删除菜单")
	@PostMapping("/del/{id}")
	public R del(@PathVariable Integer id) {
		log.debug("{}-根据ID删除", info_prefix, id);
		SysMenuService.delete(id);
		return R.ok("删除成功");
	}

	@Operation(summary = "批量删除菜单")
	@PostMapping("/delBatch")
	public R delBatch(@RequestBody List<Integer> ids) {
		SysMenuService.deleteByIds(ids);
		return R.ok("批量删除菜单成功");
	}

	@Operation(summary = "更新菜单")
	@PostMapping("update")
	public R update(@RequestBody SysMenu record) {
		log.debug("{}-保存信息: {}", info_prefix, record);
		SysMenuService.update(record);
		return R.ok("更新成功");
	}

	@Operation(summary = "查看属性")
	@GetMapping("/model")
	public SysMenu model() {
		return null;
	}

	/**
	 * 判断字段是否存在
	 *
	 * @param checkExistVo 参数
	 * @return
	 */
	@PostMapping(value = "/checkEntityExist", produces = "application/json")
	protected R checkEntityExist(@RequestBody CheckExistVo checkExistVo) {
		return this.checkExist(SysMenuService, checkExistVo);
	}


}
